package day_240428.q2;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) {
        Person person = new Person();
        Field[] fields = person.getClass().getFields();
        System.out.println(fields.length);

/*        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            System.out.println(field);
        }*/

        // 增强型 for 循环，与上面其实是完全相等的
        for (Field field : fields){
            System.out.println(field);
        }

        System.out.println("--- --- ---");

        fields = person.getClass().getDeclaredFields();

        for (Field field : fields){
            System.out.println(field);
        }

        System.out.println("--- --- ---");
        System.out.println("method");

        Method[] methods = person.getClass().getDeclaredMethods();
        // Method[] methods = person.getClass().getMethods();
        // 这里如果使用的是注释内的调用，则打印长度的时候会显示有13个...？
        System.out.println(methods.length);

        for (Method method : methods){
            System.out.println(method);
        }

        System.out.println("--- --- --- ");
        System.out.println("constructor");

        Constructor[] constructors = person.getClass().getConstructors();
        System.out.println(constructors.length);

        for (Constructor constructor : constructors){
            System.out.println(constructor);
        }
    }
}
